package ru.study.thinkin.chapter9;

import java.util.Random;

abstract class Instrument {
	protected long i = new Random().nextInt(100);
	
	public abstract void play(Note n);
	
	public String what() {return "Instrument";}
	
	public abstract void adjust();
}

class Wind extends Instrument {
	protected double j = new Random().nextDouble();
	
	@Override
	public void play(Note n) {
		System.out.println("Wind play() "+n);
	}
	@Override
	public void adjust() {}
	
	public String  what () {
		return "Wind";
	}
	
}

class Piano extends Instrument {

	@Override
	public void play(Note n) {
		 System.out.println("Piano.play() "+n);
	}

	@Override
	public void adjust() {
			
	}
	
}

class Stringed extends Instrument {

	@Override
	public void play(Note n) {
		System.out.println("Stringed play()"+n);		
	}
	@Override
	public void adjust() {
				
	}	
}

class WoodWind extends Wind {
	
	public void play(Note n) {
		System.out.println("WoodWind play() "+n);
	}
	public String what() {
		return "WoodWind";
	}
}

public class Music4 {
	
	static void tune(Instrument i) {
		i.play(Note.MIDDLE_C);
	}
	static void tuneAll(Instrument[] e) {
		for(Instrument i : e) {
			tune(i);
		}
	}
	
	public static void main(String[] args) {
		Instrument[] orchestra = new Instrument[] {new Wind(),new WoodWind(),new Piano()}; 
		//Wind[] orchestra = new Wind[] {new Wind(),new WoodWind()};
		tuneAll(orchestra);
		for(Instrument ins : orchestra) {
			System.out.print(ins.toString()+"  ");
			System.out.print(" i="+ins.i);
			//if (Wind.class.isInstance(ins)) { 
			if ( ins instanceof Wind ) {
				System.out.print(" j="+((Wind)ins).j);
			}
			System.out.println();
		}
		
	}
}
